package array;

public class leetCode922_sortArrayByParityII {
    public int[] sortArrayByParityII(int[] nums) {
        if(nums == null || nums.length < 2) return nums;
        int[] ans = new int[nums.length];

        int i = 0;
        for (int num : nums) {
            if(num % 2 == 0){
                ans[i] = num;
                i += 2;
            }
        }
        int j = 1;
        for (int num : nums) {
            if(num % 2 == 1){
                ans[j] = num;
                j += 2;
            }
        }
        return ans;

    }
}
